package com.luhan.fmmall.controller;

import com.luhan.fmmall.entity.Users;
import com.luhan.fmmall.service.UserService;
import com.luhan.fmmall.vo.ResStatus;
import com.luhan.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "提供用户注册和登录接口",tags = "用户管理")
@RestController
@RequestMapping("/user")
//设置允许跨域请求
@CrossOrigin
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",dataType = "string",required = true,value = "用户登录账号"),
            @ApiImplicitParam(name = "password",dataType = "string",required = true,value = "用户登录密码")
    })
    @GetMapping("/login")
    public ResultVO login(@RequestParam("username") String name,
                          @RequestParam("password") String password){
        return userService.checkLogin(name,password);
    }

    @ApiOperation("用户注册接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",dataType = "string",required = true,value = "用户注册账号"),
            @ApiImplicitParam(name = "password",dataType = "string",required = true,value = "用户注册密码")
    })
    @PostMapping("/regist")
    public ResultVO regist(@RequestBody Users users){
        return userService.userResgit(users.getUsername(),users.getPassword());
    }

    @GetMapping("/check")
    public ResultVO check(@RequestHeader("token")String token){
        return new ResultVO(ResStatus.OK,"success",null);
    }
}
